﻿using System;
using System.Collections.Generic;
using System.Text;

using FreeFlow.Administration;
using System.Windows.Forms;

namespace FreeFlowAdministrator
{
  public class WorkflowAdaptor : Adaptor, IDeletable
  {
    private Workflow wf;
    public WorkflowAdaptor(Workflow wf)
    {
      this.wf = wf;
    }

    public override string Text
    {
      get 
      {
        return wf.Name;
      }
    }

    public override object Object
    {
      get 
      { 
        return wf; 
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 2;
      }
    }

    public override Control GetRenderer()
    {
      WorkflowControl control = new WorkflowControl();
      control.LoadWorkflow(wf);
      control.ItemDeleted += new EventHandler(TriggerItemDeleted);
      return control;
    }

    public override void AddChildren(TreeNode node)
    {
      TreeNode versionNode = TreeNodeFactory.CreateTreeNode(new WorkflowVersionsAdaptor(wf.Versions));
      node.Nodes.Add(versionNode);
    }

    #region IDeletable Members

    public void Delete()
    {
      wf.Delete();
    }

    #endregion
  }
}
